package com.woniuxy.service.impl;

import com.github.pagehelper.PageHelper;
import com.woniuxy.dao.RbacManagerDao;
import com.github.pagehelper.PageInfo;
import com.woniuxy.entity.RbacManager;
import com.woniuxy.entity.ResponseEntity;
import com.woniuxy.service.RbacManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: java-85-course-code
 * @BelongsPackage: com.woniuxy.service.impl
 * @Author: LiTongMiao
 * @Date: 2022/2/21 15:36
 * @Description: TODO
 */
@Service
public class RbacManagerServiceImpl implements RbacManagerService {
    @Autowired(required = false)
    RbacManagerDao rbacManagerDao;

    @Override
    public ResponseEntity findAll(int currentPage,int pageSize,RbacManager rbacManager) {
        List<RbacManager> rbacManagerList = rbacManagerDao.findAll(rbacManager);
        PageHelper.startPage(currentPage, pageSize);

        PageInfo<RbacManager> of = PageInfo.of(rbacManagerList);
        ResponseEntity<PageInfo> listResponseEntity = new ResponseEntity<>();

        if (rbacManagerList.size() > 0) {
            listResponseEntity.setCode(200);
            listResponseEntity.setMsg("查詢成功");
            listResponseEntity.setData(of);
        }else {
            listResponseEntity.setCode(500);
            listResponseEntity.setMsg("数据为空");
            listResponseEntity.setData(null);
        }
        return listResponseEntity;
    }

    @Override
    public ResponseEntity deleteOne(int id) {
        int num = rbacManagerDao.deleteById(id);
        if (num > 0) {
            return new ResponseEntity<>(200,"成功删除一行数据",null);
        }else {
            return new ResponseEntity<>(500,"系统维护中",null);
        }
    }

    @Override
    public ResponseEntity addOne(RbacManager rbacManager) {
        int num = rbacManagerDao.addOne(rbacManager);
        if (num > 0) {
            return new ResponseEntity<>(200,"成功插入一行数据",null);
        }else {
            return new ResponseEntity<>(500,"系统维护中",null);

        }
    }

    @Override
    public ResponseEntity editOne(RbacManager rbacManager) {
        int num = rbacManagerDao.editOne(rbacManager);
        if (num > 0) {
            return new ResponseEntity<>(200,"成功修改一行数据",null);
        }else {
            return new ResponseEntity<>(500,"系统维护中",null);

        }
    }
}
